﻿<phone:PhoneApplicationPage
    x:Class="Catalogo.WindowsPhone.Views.HomePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewmodel="clr-namespace:Catalogo.Portable.ViewModel;assembly=Catalogo.Portable"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

    <phone:PhoneApplicationPage.Resources>
        <viewmodel:HomePageViewModel x:Key="ViewModel"/>
        <Style TargetType="Button" x:Key="EmptyButton">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ContentPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </phone:PhoneApplicationPage.Resources>
    
    <Grid x:Name="LayoutRoot">
        <phone:Panorama ItemsSource="{Binding Categorias}" x:Name="Panorama">
            <phone:Panorama.TitleTemplate>
                <DataTemplate>
                    <Border Background="#FF748181" Margin="-10,40,0,0">
                        <Image Source="/Assets/Images/Logo.png" Margin="40,0,0,0" Stretch="Uniform"/>
                    </Border>
                </DataTemplate>
            </phone:Panorama.TitleTemplate>
            <phone:Panorama.HeaderTemplate>
                <DataTemplate>
                    <Button Command="{Binding AbrirCategoriaCommand, Source={StaticResource ViewModel}}" CommandParameter="{Binding Id}" Style="{StaticResource EmptyButton}">
                        <TextBlock Text="{Binding Nome}" FontSize="40" TextWrapping="Wrap" />
                    </Button>
                </DataTemplate>
            </phone:Panorama.HeaderTemplate>
            <phone:Panorama.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <ListBox ItemsSource="{Binding Itens}" SelectionMode="Single">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Button Margin="6" Command="{Binding AbrirItemCommand, Source={StaticResource ViewModel}}" CommandParameter="{Binding Id}" Style="{StaticResource EmptyButton}">
                                        <Grid Background="#99000000">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Border Background="#66000000" Width="120" Height="120">
                                                <Image Source="{Binding ImageUrl}" Stretch="UniformToFill"/>
                                            </Border>
                                            <StackPanel Grid.Column="1" Margin="10,0,0,0">
                                                <TextBlock Text="{Binding Nome}" FontSize="26" FontWeight="Bold"  />
                                                <TextBlock Text="{Binding SubTitulo}" TextWrapping="NoWrap"/>
                                            </StackPanel>
                                        </Grid>
                                    </Button>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </DataTemplate>
            </phone:Panorama.ItemTemplate>
        </phone:Panorama>
    </Grid>

</phone:PhoneApplicationPage>